a = input()
omg = []
o = []
for l in range(1, 4+1):
    omg+=[int(a[:l])]
for l in range(2, 4+1):
    omg+=[int(a[1:l])]
for l in range(3, 4+1):
    omg+=[int(a[2:l])]
for z in omg:
    k=0
    for l in range (2,int(int(z)**0.5)+1):
        if int(z)%l==0 or int(z)==1:
            k+=1
            if k>0:o+=[0]
            else: o+=[int(z)]

print(max(o))
